/*
 * @description: 页面初始化加载函数
 * @Author: Islands
 * @Date: 2024-06-20 17:21:09
 * @LastEditTime: 2024-08-20 17:19:19
 */
import { storeToRefs } from "pinia";
import { configStore } from '@/plugins/pinia/index';
import { IPickerOption, pickerOption,LoopColor,LoopColorHover } from '@/constant/config';
import { useI18n } from "vue-i18n";
import { toRgba } from '@/utils/index';

/**
 * 初始化
 * @returns 
 */
function useInit() {
    const { Widgets } = storeToRefs(configStore());
    const { locale } = useI18n();
    const init = () => {
        //初始化加载全局主题色
        pickerOption.value.forEach((item: IPickerOption) => {
            let color = Widgets.value.colors[item.value]            
            LoopColor(item.el).forEach(i=>{                
                document.documentElement.style.setProperty(i, toRgba(color));

            })
            LoopColorHover(item.el).forEach(i=>{
                document.documentElement.style.setProperty(i, toRgba(color,0.2));

            })
        });
        //语言配置
        locale.value = Widgets.value.language.value;
        console.log("初始化成功....");
        return;
    };
    return {
        init,
    };
}
export default useInit;